/**
 * *老人信息 右侧信息展示
 * @param {any} type
 */
var arr = [];
var centerLon = 116.41667, centerLat = 39.91667//lon:经度116  lat:维度39  家庭经纬度
var homeLon = 116.41667, homeLat = 39.91667;//家庭经纬度
var currentLon = 0, currentLat = 0;//当前定位经纬度
var cover;//覆盖物
var allData;
var radius = 0;
var lineArr = [];
var homeAddress = '位置信息：初始化位置';
var currentAdress = '位置信息：初始化位置';
var isEnable = '0';
var haveSensor = false; //是否拥有传感器
function getDingweiMaphy(type) {
    //播放加载中的图标
    if (type == 1) {
    } else if (type == 3) {
    } else {
        //type:2  获取当前定位，并且发送定位请求
        $("#bottomLoading").show()
        $("#bottomIcon").hide()
    }
    var dateN = new Date().Format("yyyy-MM-dd hh:mm:ss");
    $("#dingweiTime").text("更新时间：" + dateN);
    $('#haveSersor').hide();//默认不展示
    $('#withoutSersor').show();//默认不展示
    var arr = [];
    var centerLon = 116.41667, centerLat = 39.91667//lon:经度116  lat:维度39  家庭经纬度
    var homeLon = 116.41667, homeLat = 39.91667;//家庭经纬度
    var currentLon = 0, currentLat = 0;//当前定位经纬度
    var cover;//覆盖物
    var allData;
    var radius = 0;
    var lineArr = [];
    var homeAddress = '位置信息：初始化位置';
    var currentAdress = '位置信息：初始化位置';
    var isEnable = '0';
    var haveSensor = false; //是否拥有传感器
    $('#dingweiLocation').empty();
    $('#dingweiLocation').text('暂无数据')
    //$('#jiatingLocation').empty();
    //$('#jiatingLocation').text('暂无数据')
    //获取指标信息
    $.ajax({
        url: "/Video/GetIndicator?PhoneNum=" + app.phoneNum + "&UserID=" + app.userId,
        dataType: "json",
        async: false,
        success: function (data) {
            haveSensor = false;
            if (data.code == 0) {
                let allData = data.data;
                //$('#jiatingLocation').empty();
                //$('#jiatingLocation').text('暂无数据')
                //allData.filter(item => {
                //    if (item.indicatorsId == '11') {
                //        item.indicatorsSensor.filter(i => {
                //            if (i.sensor.length > 0) {
                //                haveSensor = true
                //            }
                //        })
                //    }
                //})
                //判断是否有传感器
                if (data.code == 0) {
                    $('#withoutSersor').hide()
                    $('#haveSersor').show()
                } else {
                    $('#withoutSersor').show()
                    $('#haveSersor').hide()
                }
            }
        },
        error: function (e) {
            console.log(e)
        }
    });
    //获取栅栏信息
    $.ajax({
        url: "/Video/GetFenceDetail?UserID=" + app.userId,
        dataType: "json",
        async: false,
        success: function (data) {
            $("#mydingweiMapBox").show()
            if (data.code == 0) {
                allData = data.data
                homeLon = allData.user_home.home_lon || 0;
                homeLat = allData.user_home.home_lat || 0;
                radius = allData.fence_circle.radius
                $('#jiatingLocation').html(allData.user_home.home_address);
                if (allData.user_home.home_address.length >13) {
                    $('#jiatingLocation').css('line-height','0.4rem')
                }
                homeAddress = '家庭地址' + '\n' + '地址：' + allData.user_home.home_address;
                isEnable = allData.isEnable;
                //栅栏开启
                if (allData.isEnable == '1') {
                    $('#fenceOpen').show()
                    $('#fenceClose').hide()
                } else {
                    $('#fenceOpen').hide()
                    $('#fenceClose').show()
                }
            }
        },
        error: function (e) {
            console.log(e)
        }
    });
    //获取最新位置信息
    $.ajax({
        url: "/Video/GetLocationCurrent?UserID=" + app.userId,
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.code == 0) {
                //当前位置经度
                currentLon = data.data.current.value || homeLon;
                //当前位置维度
                currentLat = data.data.current.value1 || homeLat;
                if (data.data.current.remark) {
                    $('#dingweiLocation').html(JSON.parse(data.data.current.remark).Address);
                    currentAdress = '最新定位' + '\n' + '地址：' + JSON.parse(data.data.current.remark).Address + '\n' + '时间：' + data.data.current.time;
                }

                let sideType = data.data.fenceSideType
                //围栏状态：sideType：0-围栏内   sideType：1-围栏外  sideType：2-未知
                if (sideType == 0) {
                    $('#inSurround').show();
                    $('#outSurround').hide();
                    $('#weizhiSurround').hide();
                } else if (sideType == 1) {
                    $('#inSurround').hide();
                    $('#outSurround').show();
                    $('#weizhiSurround').hide();
                } else {
                    $('#inSurround').hide();
                    $('#outSurround').hide();
                    $('#weizhiSurround').show();
                }
            }
        },
        error: function (e) {
            console.log(e)
        }
    });

    //type:1-家的位置  2-当前定位
    if (type == 1) {
        centerLon = homeLon;
        centerLat = homeLat;
    } else {
        centerLon = currentLon;
        centerLat = currentLat;
    }
    var map = new AMap.Map('containerDingweimap', {
        resizeEnable: true, //是否监控地图容器尺寸变化
        zoom: 15, //初始化地图层级
        center: [centerLon, centerLat] //初始化地图中心点
    });
    marker = new AMap.Marker({
        map: map,
        position: new AMap.LngLat(homeLon, homeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
        title: homeAddress,
        //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
        icon: new AMap.Icon({
            size: new AMap.Size(25, 40), // 图标尺寸
            image: "/Content/img/location/markerblue.png",
            imageSize: new AMap.Size(25, 30)
        }),
    });
    //fence_type:1:多边形  2圆形  判断fence_type不为空，fence_polygons不为空。isEnable!=0 代表栅栏开启
    if (allData && allData.fence_type && allData.fence_type == 1 && allData.fence_polygons.length != 0 && isEnable != '0') {
        //绘制多边形覆盖物
        var path = [];
        var pathData = allData.fence_polygons
        pathData.forEach(item => {
            path.push(new AMap.LngLat(item.lng, item.lat))
        })
        cover = new AMap.Polygon({
            path: path,
            fillColor: '#5FD990', // 多边形填充颜色
            fillOpacity: 0.5,
            borderWeight: 2, // 线条宽度，默认为 1
            strokeColor: '#fff', // 线条颜色
            strokeOpacity: 0.5,
        });
        map.add(cover);
    } else if (allData && allData.fence_type && allData.fence_type == 2 && isEnable != '0') {

        //绘制圆形覆盖物
        cover = new AMap.Circle({
            center: new AMap.LngLat(homeLon, homeLat),  // 圆心位置
            radius: radius, // 圆半径
            fillColor: '#5FD990',   // 圆形填充颜色
            strokeColor: '#fff', // 描边颜色
            strokeWeight: 2, // 描边宽度
            fillOpacity: 0.5,
        });
        map.add(cover);
    }

    if (currentLon != 0 && currentLat != 0) {
        // 创建一个 Marker 实例：
        var currentMarker = new AMap.Marker({
            position: new AMap.LngLat(currentLon, currentLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
            title: currentAdress,
            icon: new AMap.Icon({
                size: new AMap.Size(25, 40), // 图标尺寸
                image: "/Content/img/location/markergreen.png",
                imageSize: new AMap.Size(25, 30)
            }),
        });
        // 将创建的点标记添加到已有的地图实例：
        map.add(currentMarker);
        //在家庭位置与当前位置之间绘制虚线
        lineArr.push([homeLon, homeLat])
        lineArr.push([currentLon, currentLat])
        // 绘制轨迹
        var polyline = new AMap.Polyline({
            map: map,
            path: lineArr,
            showDir: true,
            strokeColor: "#28F", //线颜色
            strokeOpacity: 1, //线透明度
            strokeWeight: 3, //线宽
            strokeStyle: "dashed" //线样式
        });
        marker.on('moving', function (e) {
            polyline.setPath(e.passedPath);
        });
    }

    map.setFitView();
    AMap.plugin('AMap.ToolBar', function () {//异步加载插件
        var toolbar = new AMap.ToolBar();
        map.addControl(toolbar);
    });
    console.log('1111', centerLon, centerLat)
    if (centerLon == 0 && centerLat == 0) {
        //如果未获取到当前位置的数据，则默认定位到北京市
      
        map.setCenter([116.41667, 39.91667]);
        map.setZoom(15)
    } else {
        //改变地图中心点
        map.setCenter([centerLon, centerLat]);
    }

    //当前定位-发送定位请求
    if (type == 2) {
        getLocationRequest()
    } else if (type == 1) {
        //家庭定位-设置地图层级，否则看不见覆盖物
        map.setZoom(15); //设置地图层级
    }
    app.setLoading(false)
}//定位信息
function getLocationRequest() {
    //发送定位请求
    $.ajax({
        url: "/Video/GetLocationCurrent?UserID=" + app.userId,
        dataType: "json",
        async: true,
        success: function (data) {
            $("#bottomLoading").hide()
            $("#bottomIcon").show()
            if (data.code != 0) {
                alert(data.message)
            }
        },
        error: function (e) {
            $("#bottomLoading").hide()
            $("#bottomIcon").show()
            console.log(e)
        }
    });
}//定位模式发送定位请求
function drawTable() {
    indextable_misscall = $('#table_calllog').DataTable({
        "language": {
            url: "/Content/trtc/js/media/zh_CN.json"
        },
        "order": [[1, "desc"]],
        "bSort": true, //是否启动各个字段的排序功能
        "info": true,
        "paging": true,
        "processing": true,
        "searching": true,
        "bPaginate": true,//分页总开关
        "bLengthChange": false, //开关，是否显示每页显示多少条数据的下拉框
        'iDisplayLength': 5, //每页初始显示5条记录
        "pagingType": "full_numbers",//分页样式
        "responsive": true,
        "destroy": true,
        serverSide: false,
        columns: [
            { data: 'appMemberName', title: '号码' },
            {
                data: 'callBeginTime', title: '时间', render: (data) => {
                    return data.replace('T', ' ')
                }
            },
            {
                data: 'null', title: '类型', render: (data) => {
                    return '呼入'
                }
            },
            {
                data: 'callTotalDurations', title: '通话时长', render: (data) => {
                    const h = parseInt(data / 3600)
                    const minute = parseInt(data / 60 % 60)
                    const second = Math.ceil(data % 60)
                    const hours = h < 10 ? '0' + h : h
                    const formatSecond = second > 59 ? 59 : second
                    return `${hours > 0 ? `${hours}:` : '00'}:${minute < 10 ? '0' + minute : minute}:${formatSecond < 10 ? '0' + formatSecond : formatSecond}`
                }
            },
            {
                data: 'requestType', title: '通讯方式', render: (data) => {
                    return data === 2 ? '视频通话' : '音频通话'
                },
            },
            {
                data: 'answerMode', title: '呼叫状态', render: (data) => {
                    return (data === 4 || data === 5) ? '接听' : '未接听' //3未接听   5接听
                }
            },
            {
                data: 'null', title: '操作', render: (data, type, row, meta) => {
                    return '回拨'
                }
            },
            {
                data: 'isRespond', title: '处理状态', render: (data, type, row, meta) => {
                    return data === 1 ? '已处理' : '未处理'
                }
            },
            {
                data: 'processMessage', title: '处理意见', width: '10%'
            },
        ],
        fnCreatedRow: function (nRow, aData, iDataIndex) {
            if (aData.answerMode !== 4 && aData.answerMode !== 5) {
                $(nRow).css("color", 'red')
            } else {
                $(nRow).css("color", 'green')
            }
        },
        ajax: {
            url: "/Video/GetUserAppCallNumRecords",
            type: "GET",
            dataType: 'json',
            data: {
                DateBegin: new Date().Format("yyyy-MM-dd 00:00:00"),
                DateEnd: new Date().Format("yyyy-MM-dd 23:59:59"),
                serviceCallNum: $('#userId')[0].value,
                CallSatus: 3,
            },
            dataSrc: function (data) {
                if (data) {
                    $(data).each((index, item) => {
                        //let HomePopup = new Base({ userId: item.appMemberName, index: index });
                        //HomePopup.missCallNotify()
                    })
                }
                return data
            },
        }
    });
    $('#search').on('click', function () {
        table.draw();
    });
} // 通话记录表格 √ 如果报错则放到index页面
$('#icon-refresh').click(function () {
    drawTable();
    //  indextable_misscall.draw(true);
})//刷新通话记录
function initMap(type) {
    //播放加载中的图标
  
    var dateN = new Date().Format("yyyy-MM-dd hh:mm:ss");
    $("#dingweiTime").text("更新时间：" + dateN);
    $('#haveSersor').hide();//默认不展示
    $('#withoutSersor').show();//默认不展示
    var arr = [];
    var centerLon = 116.41667, centerLat = 39.91667//lon:经度116  lat:维度39  家庭经纬度
    var homeLon = 116.41667, homeLat = 39.91667;//家庭经纬度
    var currentLon = 0, currentLat = 0;//当前定位经纬度
    var cover;//覆盖物
    var allData;
    var radius = 0;
    var lineArr = [];
    var homeAddress = '位置信息：初始化位置';
    var currentAdress = '位置信息：初始化位置';
    var isEnable = '0';
    var haveSensor = false; //是否拥有传感器
    $('#dingweiLocation').empty();
    $('#dingweiLocation').text('暂无数据')
    //$('#jiatingLocation').empty();
    //$('#jiatingLocation').text('暂无数据')
  

    //type:1-家的位置  2-当前定位
    centerLon = currentLon;
    centerLat = currentLat;
    
    var map = new AMap.Map('containerDingweimap', {
        resizeEnable: true, //是否监控地图容器尺寸变化
        zoom: 15, //初始化地图层级
        center: [centerLon, centerLat] //初始化地图中心点
    });
    marker = new AMap.Marker({
        map: map,
        position: new AMap.LngLat(homeLon, homeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
        title: homeAddress,
        //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
        icon: new AMap.Icon({
            size: new AMap.Size(25, 40), // 图标尺寸
            image: "/Content/img/location/markerblue.png",
            imageSize: new AMap.Size(25, 30)
        }),
    });
    //fence_type:1:多边形  2圆形  判断fence_type不为空，fence_polygons不为空。isEnable!=0 代表栅栏开启
    if (allData && allData.fence_type && allData.fence_type == 1 && allData.fence_polygons.length != 0 && isEnable != '0') {
        //绘制多边形覆盖物
        var path = [];
        var pathData = allData.fence_polygons
        pathData.forEach(item => {
            path.push(new AMap.LngLat(item.lng, item.lat))
        })
        cover = new AMap.Polygon({
            path: path,
            fillColor: '#5FD990', // 多边形填充颜色
            fillOpacity: 0.5,
            borderWeight: 2, // 线条宽度，默认为 1
            strokeColor: '#fff', // 线条颜色
            strokeOpacity: 0.5,
        });
        map.add(cover);
    } else if (allData && allData.fence_type && allData.fence_type == 2 && isEnable != '0') {

        //绘制圆形覆盖物
        cover = new AMap.Circle({
            center: new AMap.LngLat(homeLon, homeLat),  // 圆心位置
            radius: radius, // 圆半径
            fillColor: '#5FD990',   // 圆形填充颜色
            strokeColor: '#fff', // 描边颜色
            strokeWeight: 2, // 描边宽度
            fillOpacity: 0.5,
        });
        map.add(cover);
    }

    if (currentLon != 0 && currentLat != 0) {
        // 创建一个 Marker 实例：
        var currentMarker = new AMap.Marker({
            position: new AMap.LngLat(currentLon, currentLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
            title: currentAdress,
            icon: new AMap.Icon({
                size: new AMap.Size(25, 40), // 图标尺寸
                image: "/Content/img/location/markergreen.png",
                imageSize: new AMap.Size(25, 30)
            }),
        });
        // 将创建的点标记添加到已有的地图实例：
        map.add(currentMarker);
        //在家庭位置与当前位置之间绘制虚线
        lineArr.push([homeLon, homeLat])
        lineArr.push([currentLon, currentLat])
        // 绘制轨迹
        var polyline = new AMap.Polyline({
            map: map,
            path: lineArr,
            showDir: true,
            strokeColor: "#28F", //线颜色
            strokeOpacity: 1, //线透明度
            strokeWeight: 3, //线宽
            strokeStyle: "dashed" //线样式
        });
        marker.on('moving', function (e) {
            polyline.setPath(e.passedPath);
        });
    }

    map.setFitView();
    AMap.plugin('AMap.ToolBar', function () {//异步加载插件
        var toolbar = new AMap.ToolBar();
        map.addControl(toolbar);
    });
    console.log('1111', centerLon, centerLat)
    if (centerLon == 0 && centerLat == 0) {
        //如果未获取到当前位置的数据，则默认定位到北京市

        map.setCenter([116.41667, 39.91667]);
        map.setZoom(15)
    } else {
        //改变地图中心点
        map.setCenter([centerLon, centerLat]);
    }

    //当前定位-发送定位请求
    if (type == 2) {
        getLocationRequest()
    } else if (type == 1) {
        //家庭定位-设置地图层级，否则看不见覆盖物
        map.setZoom(15); //设置地图层级
    }
    app.setLoading(false)
}//初始话地图
function getDingweiMap3(type) {
    //播放加载中的图标
    if (type == 1) {
    } else if (type == 3) {
    } else {
        //type:2  获取当前定位，并且发送定位请求
        $("#bottomLoading").show()
        $("#bottomIcon").hide()
    }
    var dateN = new Date().Format("yyyy-MM-dd hh:mm:ss");
    $("#dingweiTime").text("更新时间：" + dateN);
    $('#haveSersor').hide();//默认不展示
    $('#withoutSersor').show();//默认不展示
    var arr = [];
    var centerLon = 116.41667, centerLat = 39.91667//lon:经度116  lat:维度39  家庭经纬度
    var homeLon = 116.41667, homeLat = 39.91667;//家庭经纬度
    var currentLon = 0, currentLat = 0;//当前定位经纬度
    var cover;//覆盖物
    var allData;
    var radius = 0;
    var lineArr = [];
    var homeAddress = '位置信息：初始化位置';
    var currentAdress = '位置信息：初始化位置';
    var isEnable = '0';
    var haveSensor = false; //是否拥有传感器
    $('#dingweiLocation').empty();
    $('#dingweiLocation').text('暂无数据')
    //$('#jiatingLocation').empty();
    //$('#jiatingLocation').text('暂无数据')
    //获取指标信息
    $.ajax({
        url: "/Video/GetIndicator?PhoneNum=" + app.phoneNum + "&UserID=" + app.userId,
        dataType: "json",
        async: true,
        success: function (data) {
            haveSensor = false;
            if (data.code == 0) {
                let allData = data.data;
                //$('#jiatingLocation').empty();
                //$('#jiatingLocation').text('暂无数据')
                //allData.filter(item => {
                //    if (item.indicatorsId == '11') {
                //        item.indicatorsSensor.filter(i => {
                //            if (i.sensor.length > 0) {
                //                haveSensor = true
                //            }
                //        })
                //    }
                //})
                //判断是否有传感器
                if (data.code == 0) {
                    $('#withoutSersor').hide()
                    $('#haveSersor').show()
                } else {
                    $('#withoutSersor').show()
                    $('#haveSersor').hide()
                }
            }
            //获取栅栏信息
            $.ajax({
                url: "/Video/GetFenceDetail?UserID=" + app.userId,
                dataType: "json",
                async: true,
                success: function (data) {
                    $("#mydingweiMapBox").show()
                    if (data.code == 0) {
                        allData = data.data
                        homeLon = allData.user_home.home_lon || 0;
                        homeLat = allData.user_home.home_lat || 0;
                        radius = allData.fence_circle.radius
                        $('#jiatingLocation').html(allData.user_home.home_address);
                        if (allData.user_home.home_address.length > 13) {
                            $('#jiatingLocation').css('line-height', '0.4rem')
                        }
                        homeAddress = '家庭地址' + '\n' + '地址：' + allData.user_home.home_address;
                        isEnable = allData.isEnable;
                        //栅栏开启
                        if (allData.isEnable == '1') {
                            $('#fenceOpen').show()
                            $('#fenceClose').hide()
                        } else {
                            $('#fenceOpen').hide()
                            $('#fenceClose').show()
                        }
                    }
                    //获取最新位置信息
                    $.ajax({
                        url: "/Video/GetLocationCurrent?UserID=" + app.userId,
                        dataType: "json",
                        async: true,
                        success: function (data) {
                            if (data.code == 0) {
                                //当前位置经度
                                currentLon = data.data.current.value || homeLon;
                                //当前位置维度
                                currentLat = data.data.current.value1 || homeLat;
                                if (data.data.current.remark) {
                                    $('#dingweiLocation').html(JSON.parse(data.data.current.remark).Address);
                                    currentAdress = '最新定位' + '\n' + '地址：' + JSON.parse(data.data.current.remark).Address + '\n' + '时间：' + data.data.current.time;
                                }

                                let sideType = data.data.fenceSideType
                                //围栏状态：sideType：0-围栏内   sideType：1-围栏外  sideType：2-未知
                                if (sideType == 0) {
                                    $('#inSurround').show();
                                    $('#outSurround').hide();
                                    $('#weizhiSurround').hide();
                                } else if (sideType == 1) {
                                    $('#inSurround').hide();
                                    $('#outSurround').show();
                                    $('#weizhiSurround').hide();
                                } else {
                                    $('#inSurround').hide();
                                    $('#outSurround').hide();
                                    $('#weizhiSurround').show();
                                }
                            }
                            //type:1-家的位置  2-当前定位
                            if (type == 1) {
                                centerLon = homeLon;
                                centerLat = homeLat;
                            } else {
                                centerLon = currentLon;
                                centerLat = currentLat;
                            }
                            var map = new AMap.Map('containerDingweimap', {
                                resizeEnable: true, //是否监控地图容器尺寸变化
                                zoom: 15, //初始化地图层级
                                center: [centerLon, centerLat] //初始化地图中心点
                            });
                            marker = new AMap.Marker({
                                map: map,
                                position: new AMap.LngLat(homeLon, homeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                                title: homeAddress,
                                //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
                                icon: new AMap.Icon({
                                    size: new AMap.Size(25, 40), // 图标尺寸
                                    image: "/Content/img/location/markerblue.png",
                                    imageSize: new AMap.Size(25, 30)
                                }),
                            });
                            //fence_type:1:多边形  2圆形  判断fence_type不为空，fence_polygons不为空。isEnable!=0 代表栅栏开启
                            if (allData && allData.fence_type && allData.fence_type == 1 && allData.fence_polygons.length != 0 && isEnable != '0') {
                                //绘制多边形覆盖物
                                var path = [];
                                var pathData = allData.fence_polygons
                                pathData.forEach(item => {
                                    path.push(new AMap.LngLat(item.lng, item.lat))
                                })
                                cover = new AMap.Polygon({
                                    path: path,
                                    fillColor: '#5FD990', // 多边形填充颜色
                                    fillOpacity: 0.5,
                                    borderWeight: 2, // 线条宽度，默认为 1
                                    strokeColor: '#fff', // 线条颜色
                                    strokeOpacity: 0.5,
                                });
                                map.add(cover);
                            } else if (allData && allData.fence_type && allData.fence_type == 2 && isEnable != '0') {

                                //绘制圆形覆盖物
                                cover = new AMap.Circle({
                                    center: new AMap.LngLat(homeLon, homeLat),  // 圆心位置
                                    radius: radius, // 圆半径
                                    fillColor: '#5FD990',   // 圆形填充颜色
                                    strokeColor: '#fff', // 描边颜色
                                    strokeWeight: 2, // 描边宽度
                                    fillOpacity: 0.5,
                                });
                                map.add(cover);
                            }

                            if (currentLon != 0 && currentLat != 0) {
                                // 创建一个 Marker 实例：
                                var currentMarker = new AMap.Marker({
                                    position: new AMap.LngLat(currentLon, currentLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                                    title: currentAdress,
                                    icon: new AMap.Icon({
                                        size: new AMap.Size(25, 40), // 图标尺寸
                                        image: "/Content/img/location/markergreen.png",
                                        imageSize: new AMap.Size(25, 30)
                                    }),
                                });
                                // 将创建的点标记添加到已有的地图实例：
                                map.add(currentMarker);
                                //在家庭位置与当前位置之间绘制虚线
                                lineArr.push([homeLon, homeLat])
                                lineArr.push([currentLon, currentLat])
                                // 绘制轨迹
                                var polyline = new AMap.Polyline({
                                    map: map,
                                    path: lineArr,
                                    showDir: true,
                                    strokeColor: "#28F", //线颜色
                                    strokeOpacity: 1, //线透明度
                                    strokeWeight: 3, //线宽
                                    strokeStyle: "dashed" //线样式
                                });
                                marker.on('moving', function (e) {
                                    polyline.setPath(e.passedPath);
                                });
                            }

                            map.setFitView();
                            AMap.plugin('AMap.ToolBar', function () {//异步加载插件
                                var toolbar = new AMap.ToolBar();
                                map.addControl(toolbar);
                            });
                            console.log('1111', centerLon, centerLat)
                            if (centerLon == 0 && centerLat == 0) {
                                //如果未获取到当前位置的数据，则默认定位到北京市

                                map.setCenter([116.41667, 39.91667]);
                                map.setZoom(15)
                            } else {
                                //改变地图中心点
                                map.setCenter([centerLon, centerLat]);
                            }

                            //当前定位-发送定位请求
                            if (type == 2) {
                                getLocationRequest()
                            } else if (type == 1) {
                                //家庭定位-设置地图层级，否则看不见覆盖物
                                map.setZoom(15); //设置地图层级
                            }
                            app.setLoading(false)
                        },
                        error: function (e) {
                            console.log(e)
                        }
                    });
                },
                error: function (e) {
                    console.log(e)
                }
            });
        },
        error: function (e) {
            console.log(e)
        }
    });
  
 
} //定时执行
function getDingweiMap1(type) {
    //获取指标信息
    $.ajax({
        url: "/Video/GetIndicator?PhoneNum=" + app.phoneNum + "&UserID=" + app.userId,
        dataType: "json",
        async: true,
        success: function (data) {
            haveSensor = false;
            if (data.code == 0) {
                let allData = data.data;
                //$('#jiatingLocation').empty();
                //$('#jiatingLocation').text('暂无数据')
                //allData.filter(item => {
                //    if (item.indicatorsId == '11') {
                //        item.indicatorsSensor.filter(i => {
                //            if (i.sensor.length > 0) {
                //                haveSensor = true
                //            }
                //        })
                //    }
                //})
                //判断是否有传感器
                if (data.code == 0) {
                    $('#withoutSersor').hide()
                    $('#haveSersor').show()
                } else {
                    $('#withoutSersor').show()
                    $('#haveSersor').hide()
                }
            }
        },
        error: function (e) {
            console.log(e)
        }
    });
    //获取栅栏信息
    $.ajax({
        url: "/Video/GetFenceDetail?UserID=" + app.userId,
        dataType: "json",
        async: true,
        success: function (data) {
            $("#mydingweiMapBox").show()
            if (data.code == 0) {
                allData = data.data
                homeLon = allData.user_home.home_lon || 0;
                homeLat = allData.user_home.home_lat || 0;
                radius = allData.fence_circle.radius
                $('#jiatingLocation').html(allData.user_home.home_address);
                if (allData.user_home.home_address.length > 13) {
                    $('#jiatingLocation').css('line-height', '0.4rem')
                }
                homeAddress = '家庭地址' + '\n' + '地址：' + allData.user_home.home_address;
                isEnable = allData.isEnable;
                //栅栏开启
                if (allData.isEnable == '1') {
                    $('#fenceOpen').show()
                    $('#fenceClose').hide()
                } else {
                    $('#fenceOpen').hide()
                    $('#fenceClose').show()
                }
            }
            //type:1-家的位置  2-当前定位
            if (type == 1) {
                centerLon = homeLon;
                centerLat = homeLat;
            } else {
                centerLon = currentLon;
                centerLat = currentLat;
            }
            var map = new AMap.Map('containerDingweimap', {
                resizeEnable: true, //是否监控地图容器尺寸变化
                zoom: 15, //初始化地图层级
                center: [centerLon, centerLat] //初始化地图中心点
            });
            marker = new AMap.Marker({
                map: map,
                position: new AMap.LngLat(homeLon, homeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                title: homeAddress,
                //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
                icon: new AMap.Icon({
                    size: new AMap.Size(25, 40), // 图标尺寸
                    image: "/Content/img/location/markerblue.png",
                    imageSize: new AMap.Size(25, 30)
                }),
            });
            //fence_type:1:多边形  2圆形  判断fence_type不为空，fence_polygons不为空。isEnable!=0 代表栅栏开启
            if (allData && allData.fence_type && allData.fence_type == 1 && allData.fence_polygons.length != 0 && isEnable != '0') {
                //绘制多边形覆盖物
                var path = [];
                var pathData = allData.fence_polygons
                pathData.forEach(item => {
                    path.push(new AMap.LngLat(item.lng, item.lat))
                })
                cover = new AMap.Polygon({
                    path: path,
                    fillColor: '#5FD990', // 多边形填充颜色
                    fillOpacity: 0.5,
                    borderWeight: 2, // 线条宽度，默认为 1
                    strokeColor: '#fff', // 线条颜色
                    strokeOpacity: 0.5,
                });
                map.add(cover);
            } else if (allData && allData.fence_type && allData.fence_type == 2 && isEnable != '0') {

                //绘制圆形覆盖物
                cover = new AMap.Circle({
                    center: new AMap.LngLat(homeLon, homeLat),  // 圆心位置
                    radius: radius, // 圆半径
                    fillColor: '#5FD990',   // 圆形填充颜色
                    strokeColor: '#fff', // 描边颜色
                    strokeWeight: 2, // 描边宽度
                    fillOpacity: 0.5,
                });
                map.add(cover);
            }

            if (currentLon != 0 && currentLat != 0) {
                // 创建一个 Marker 实例：
                var currentMarker = new AMap.Marker({
                    position: new AMap.LngLat(currentLon, currentLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                    title: currentAdress,
                    icon: new AMap.Icon({
                        size: new AMap.Size(25, 40), // 图标尺寸
                        image: "/Content/img/location/markergreen.png",
                        imageSize: new AMap.Size(25, 30)
                    }),
                });
                // 将创建的点标记添加到已有的地图实例：
                map.add(currentMarker);
                //在家庭位置与当前位置之间绘制虚线
                lineArr.push([homeLon, homeLat])
                lineArr.push([currentLon, currentLat])
                // 绘制轨迹
                var polyline = new AMap.Polyline({
                    map: map,
                    path: lineArr,
                    showDir: true,
                    strokeColor: "#28F", //线颜色
                    strokeOpacity: 1, //线透明度
                    strokeWeight: 3, //线宽
                    strokeStyle: "dashed" //线样式
                });
                marker.on('moving', function (e) {
                    polyline.setPath(e.passedPath);
                });
            }

            map.setFitView();
            AMap.plugin('AMap.ToolBar', function () {//异步加载插件
                var toolbar = new AMap.ToolBar();
                map.addControl(toolbar);
            });
            console.log('1111', centerLon, centerLat)
            if (centerLon == 0 && centerLat == 0) {
                //如果未获取到当前位置的数据，则默认定位到北京市

                map.setCenter([116.41667, 39.91667]);
                map.setZoom(15)
            } else {
                //改变地图中心点
                map.setCenter([centerLon, centerLat]);
            }

            //当前定位-发送定位请求
            if (type == 2) {
                getLocationRequest()
            } else if (type == 1) {
                //家庭定位-设置地图层级，否则看不见覆盖物
                map.setZoom(15); //设置地图层级
            }
            app.setLoading(false)
        },
        error: function (e) {
            console.log(e)
        }
    });
}//家庭定位信息
function getDingweiMap2(type) {
    //获取指标信息
    $.ajax({
        url: "/Video/GetIndicator?PhoneNum=" + app.phoneNum + "&UserID=" + app.userId,
        dataType: "json",
        async: true,
        success: function (data) {
            haveSensor = false;
            if (data.code == 0) {
                let allData = data.data;
                //$('#jiatingLocation').empty();
                //$('#jiatingLocation').text('暂无数据')
                //allData.filter(item => {
                //    if (item.indicatorsId == '11') {
                //        item.indicatorsSensor.filter(i => {
                //            if (i.sensor.length > 0) {
                //                haveSensor = true
                //            }
                //        })
                //    }
                //})
                //判断是否有传感器
                if (data.code == 0) {
                    $('#withoutSersor').hide()
                    $('#haveSersor').show()
                } else {
                    $('#withoutSersor').show()
                    $('#haveSersor').hide()
                }
            }
          
        },
        error: function (e) {
            console.log(e)
        }
    });
    //获取最新位置信息
    $.ajax({
        url: "/Video/GetLocationCurrent?UserID=" + app.userId,
        dataType: "json",
        async: true,
        success: function (data) {
            if (data.code == 0) {
                //当前位置经度
                currentLon = data.data.current.value || homeLon;
                //当前位置维度
                currentLat = data.data.current.value1 || homeLat;
                if (data.data.current.remark) {
                    $('#dingweiLocation').html(JSON.parse(data.data.current.remark).Address);
                    currentAdress = '最新定位' + '\n' + '地址：' + JSON.parse(data.data.current.remark).Address + '\n' + '时间：' + data.data.current.time;
                }

                let sideType = data.data.fenceSideType
                //围栏状态：sideType：0-围栏内   sideType：1-围栏外  sideType：2-未知
                if (sideType == 0) {
                    $('#inSurround').show();
                    $('#outSurround').hide();
                    $('#weizhiSurround').hide();
                } else if (sideType == 1) {
                    $('#inSurround').hide();
                    $('#outSurround').show();
                    $('#weizhiSurround').hide();
                } else {
                    $('#inSurround').hide();
                    $('#outSurround').hide();
                    $('#weizhiSurround').show();
                }
            }
            //type:1-家的位置  2-当前定位
            if (type == 1) {
                centerLon = homeLon;
                centerLat = homeLat;
            } else {
                centerLon = currentLon;
                centerLat = currentLat;
            }
            var map = new AMap.Map('containerDingweimap', {
                resizeEnable: true, //是否监控地图容器尺寸变化
                zoom: 15, //初始化地图层级
                center: [centerLon, centerLat] //初始化地图中心点
            });
            marker = new AMap.Marker({
                map: map,
                position: new AMap.LngLat(homeLon, homeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                title: homeAddress,
                //icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
                icon: new AMap.Icon({
                    size: new AMap.Size(25, 40), // 图标尺寸
                    image: "/Content/img/location/markerblue.png",
                    imageSize: new AMap.Size(25, 30)
                }),
            });
            //fence_type:1:多边形  2圆形  判断fence_type不为空，fence_polygons不为空。isEnable!=0 代表栅栏开启
            if (allData && allData.fence_type && allData.fence_type == 1 && allData.fence_polygons.length != 0 && isEnable != '0') {
                //绘制多边形覆盖物
                var path = [];
                var pathData = allData.fence_polygons
                pathData.forEach(item => {
                    path.push(new AMap.LngLat(item.lng, item.lat))
                })
                cover = new AMap.Polygon({
                    path: path,
                    fillColor: '#5FD990', // 多边形填充颜色
                    fillOpacity: 0.5,
                    borderWeight: 2, // 线条宽度，默认为 1
                    strokeColor: '#fff', // 线条颜色
                    strokeOpacity: 0.5,
                });
                map.add(cover);
            } else if (allData && allData.fence_type && allData.fence_type == 2 && isEnable != '0') {

                //绘制圆形覆盖物
                cover = new AMap.Circle({
                    center: new AMap.LngLat(homeLon, homeLat),  // 圆心位置
                    radius: radius, // 圆半径
                    fillColor: '#5FD990',   // 圆形填充颜色
                    strokeColor: '#fff', // 描边颜色
                    strokeWeight: 2, // 描边宽度
                    fillOpacity: 0.5,
                });
                map.add(cover);
            }

            if (currentLon != 0 && currentLat != 0) {
                // 创建一个 Marker 实例：
                var currentMarker = new AMap.Marker({
                    position: new AMap.LngLat(currentLon, currentLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
                    title: currentAdress,
                    icon: new AMap.Icon({
                        size: new AMap.Size(25, 40), // 图标尺寸
                        image: "/Content/img/location/markergreen.png",
                        imageSize: new AMap.Size(25, 30)
                    }),
                });
                // 将创建的点标记添加到已有的地图实例：
                map.add(currentMarker);
                //在家庭位置与当前位置之间绘制虚线
                lineArr.push([homeLon, homeLat])
                lineArr.push([currentLon, currentLat])
                // 绘制轨迹
                var polyline = new AMap.Polyline({
                    map: map,
                    path: lineArr,
                    showDir: true,
                    strokeColor: "#28F", //线颜色
                    strokeOpacity: 1, //线透明度
                    strokeWeight: 3, //线宽
                    strokeStyle: "dashed" //线样式
                });
                marker.on('moving', function (e) {
                    polyline.setPath(e.passedPath);
                });
            }

            map.setFitView();
            AMap.plugin('AMap.ToolBar', function () {//异步加载插件
                var toolbar = new AMap.ToolBar();
                map.addControl(toolbar);
            });
            console.log('1111', centerLon, centerLat)
            if (centerLon == 0 && centerLat == 0) {
                //如果未获取到当前位置的数据，则默认定位到北京市

                map.setCenter([116.41667, 39.91667]);
                map.setZoom(15)
            } else {
                //改变地图中心点
                map.setCenter([centerLon, centerLat]);
            }

            //当前定位-发送定位请求
            if (type == 2) {
                getLocationRequest()
            } else if (type == 1) {
                //家庭定位-设置地图层级，否则看不见覆盖物
                map.setZoom(15); //设置地图层级
            }
            app.setLoading(false)
        },
        error: function (e) {
            console.log(e)
        }
    });
}//当前定位信息
